package com.foxconn.ipebg.common.base.security;

import ipebg.mzk.facade.system.service.LoginService;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service("userDetailsService")
public class SecurityUserDeitailsService implements UserDetailsService {
	
	private static Logger log = LoggerFactory.getLogger(LoginAuthenticationSuccessHandler.class);
	/**
	 * 
	 */
	@Resource(name = "loginServiceImpl")
	private LoginService loginService;

	@Override
	
	public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
		UserDetails user = null;
		try {
			System.out.println("enter loadUserByUsername.");
			user = (UserDetails) loginService.getUserByUserName(userName);

		} catch (Exception e) {
			e.printStackTrace();
			log.error("Get UserDetails info by userName failed,please check DTO and network connection.");
		}
		return user;
	}
}
